package com.qf.controller;

import com.qf.enums.AppTypeCodeEnum ;
import com.qf.pojo.DataDictionary ;
import com.qf.utils.ResultVoUtil ;
import com.qf.vo.AppDownloadsVO ;
import com.qf.vo.ResultVo ;
import com.qf.service.AppInfoService;
import com.qf.service.DataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static com.qf.constant.AppConstant.*;


@Controller
@RequestMapping("/dev/app")
public class DevAppController {

    @Autowired
    private AppInfoService appInfoService;

    @Autowired
    private DataDictionaryService dataDictionaryService;


    // 开发者App首页
    @GetMapping("/index")
    public String index(){
        return DEV_APP_INDEX;
    }


    // 查询APP的下载量TOP Five
    @GetMapping("/app-download-top-five")
    @ResponseBody
    public ResultVo appDownloadTopFive(){
        //1. 调用service查询APP下载量的TOP Five
        List<AppDownloadsVO> data = appInfoService.findAppDownloadTopFive();
        //2. 响应json
        return ResultVoUtil.success(data);
    }


    // 跳转到APP维护页面
    @GetMapping("/app-maintain")
    public String appMaintain(Model model){
        // 1. 查询所属平台.
        List<DataDictionary> flatFormList = dataDictionaryService.findByTypeCode(AppTypeCodeEnum.APP_FLATFORM.getTypeCode());
        model.addAttribute("flatFormList",flatFormList);
        // 2. APP的状态



        // 3. 查询一级分类.

        return DEV_APP_MAINTAIN;
    }

}
